<?php

namespace component\system\system_role;

use common\model\Model;

/**
 * Class SystemRoleModel
 * @package component\system\system_role
 * @property integer $id
 * @property string $title
 * @property string $desc
 * @property string $auth
 * @property string $menu
 * @property integer $create_time
 * @property integer $update_time
 * @property integer $delete_time
 */
class SystemRoleModel extends Model
{
    protected $table = 'system_role';

    protected $schema = [
        'id' => 'integer',
        'title' => 'string',
        'desc' => 'string',
        'auth' => 'string',
        'menu' => 'string',
        'create_time' => 'integer',
        'update_time' => 'integer',
        'delete_time' => 'integer',
    ];

    /**
     * @param $value
     * @return string
     */
    protected function setAuthAttr($value)
    {
        if (is_array($value) && $value) {
            $value = implode(',', $value);
        } else {
            $value = '';
        }

        return $value;
    }

    /**
     * @param $value
     * @return string
     */
    protected function getAuthAttr($value)
    {
        if ($value) {
            $value = explode(',', $value);
        } else {
            $value = '';
        }

        return $value;
    }

    /**
     * @param $value
     * @return string
     */
    protected function setMenuAttr($value)
    {
        if (is_array($value) && $value) {
            $value = implode(',', $value);
        } else {
            $value = '';
        }

        return $value;
    }

    /**
     * @param $value
     * @return string
     */
    protected function getMenuAttr($value)
    {
        if ($value) {
            $value = explode(',', $value);
        } else {
            $value = '';
        }

        return $value;
    }
}    